<%@page import="Bean.memberBean"%>
<%@page import="paging.Paging"%>
<%@page import="Bean.mboardsBean"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String myContext = request.getContextPath();
%>
<%
	request.setCharacterEncoding("utf-8") ;
	String separator= "<tr bgcolor='#003366'><td height='0.2' colspan='10'></td></tr>";
%>
<jsp:useBean id="Mbdao" class="dao.mboardsDao" />

<%
	//	HttpSession session = getSession();
// 	memberBean mbean = (memberBean)session.getAttribute("member"); 
// 	String mid = mbean.getMid();

	/* out.println("mid = " + mid); */
	
	String pageNumber = request.getParameter("pageNumber") ;
	String pageSize = request.getParameter("pageSize") ;
	int totalCount = Mbdao.getTotalCount() ; //1000 ;
		
	String url = "list.mb";
		
	Paging pageInfo = new Paging(pageNumber, pageSize, totalCount, url); 
	
	/* 보드 리스트 보여주는 코드 */
	ArrayList<mboardsBean> lists 
		= Mbdao.getMboardsList( pageInfo.getBeginRow(), pageInfo.getEndRow() ) ;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="./css/Design.css" rel="stylesheet" type="text/css">
<title>nfList</title>
<style>
.sortable {
	font-size: medium;
	font-family: 맑은 고딕;
	margin: 0px 0px 50px 0px;
}

.twoCol {
	margin: 0px 0px 0px 0px;
}
</style>
<script type="text/javascript">		
		function writeForm(){
			location.href='/insert.mb';
		}
		function replyData( groupno, orderno, pageNumber ){
			 var viewPage = 'jsp/mboards/mboardsReplyForm.jsp?groupno=' + groupno + "&orderno=" + orderno ; 
			 viewPage += '&pageNumber=' + pageNumber ;
			 location.href = viewPage ;
		}
		function Move(){
		
			location.href="<%=myContext%>/jsp/mboards/mboardsWriteForm.jsp";
		}
					
	</script>
</head>
<body class="twoCol">
	<jsp:include page="../main/upMenu.jsp" />
	<div id="wrapper">
		<div id="subhead">
			<a href="<%=myContext%>/startHome.main"><img src="./jsp/image/subLogo.gif" /></a>
		</div>
		<div id="submenu"></div>

		<div>
			<table border="0" class="sortable" width="700">
				<tr>
					<th width="50">글번호</th>
					<th>회원ID</th>
					<th>제목</th>
					<th>작성일</th>
					<th width="40">댓글</th>
				</tr>
				<!-- separator은 두꺼운 줄 -->
				<%=separator%>
				<tr>
					<td colspan="5" align="right"><%=pageInfo.getPagingStatus()%>
					</td>
				</tr>
				<!-- 보드리스트 출력  -->
				<!-- level을 통해 댓글의 깊이 설정 -->
				<%
					for (mboardsBean MbBean : lists) {
						int level = MbBean.getLevel();
						String temp = ""; // 댓글의 깊이에 따라서 [re :] 문자를 붙여 준다. 
						for (int i = 0; i < level; i++) {
							temp += "→ re : ";
						}
				%>
				<!-- separator은 두꺼운 줄 -->
				<%=separator%>
				<tr>
					<!-- 게시글 번호 -->
					<td align="center"><%=MbBean.getMbnum()%></td>

					<!-- 게시글 회원 아이디-->
					<td align="center"><%=MbBean.getMid()%></td>

					<td><font color="red"><%=temp%></font>[<%=MbBean.getMbcategory()%>]
						<a
						href="<%=myContext%>/view.mb?mbnum=<%=MbBean.getMbnum()%>&pageNumber=<%=pageInfo.getPageNumber()%>">
							<strong><%=MbBean.getMbtitle()%></strong>
					</a></td>

					<td align="center"><%=MbBean.getMbdate()%></td>
					<td align="center"><input type="button" value="댓글" onclick="replyData(<%=MbBean.getGroupno()%>, <%=MbBean.getOrderno()%>, <%=pageInfo.getPageNumber()%>)">
					</td>
				</tr>
				<%
					}
				%>
				<!-- for문의 끝 -->
				<!-- separator은 두꺼운 줄 -->
				<%=separator%>
				<tr>
					<td colspan="4" align="center"><%=pageInfo.getPagingHtml()%></td>
					<td colspan="1" align="right"><input type="button" value="글쓰기" onclick="Move();" /></td>
				</tr>
			</table>
		</div>

		<div id="siteDown">
			<img src="./jsp/image/footer.gif">
		</div>
	</div>
</body>
</html>










